import { config } from 'dotenv';
import { DataSource } from 'typeorm';
import { dataSourceOptions } from '../../config/data-source';

// 加载环境变量
config();

async function checkData() {
  console.log('正在连接数据库...');
  
  const dataSource = new DataSource(dataSourceOptions);
  await dataSource.initialize();
  
  try {
    console.log('检查数据...');
    
    // 检查标签数量
    const tagsCount = await dataSource.query('SELECT COUNT(*) as count FROM tags');
    console.log(`标签数量: ${tagsCount[0].count}`);
    
    // 检查任务数量
    const tasksCount = await dataSource.query('SELECT COUNT(*) as count FROM tasks');
    console.log(`任务数量: ${tasksCount[0].count}`);
    
    // 检查项目数量
    const projectsCount = await dataSource.query('SELECT COUNT(*) as count FROM projects');
    console.log(`项目数量: ${projectsCount[0].count}`);
    
    // 检查任务标签关联数量
    const taskTagsCount = await dataSource.query('SELECT COUNT(*) as count FROM task_tags');
    console.log(`任务标签关联数量: ${taskTagsCount[0].count}`);
    
    // 获取几个标签样本
    console.log('\n标签样本:');
    const tags = await dataSource.query('SELECT * FROM tags LIMIT 3');
    console.log(tags);
    
    // 获取几个任务样本
    console.log('\n任务样本:');
    const tasks = await dataSource.query('SELECT * FROM tasks LIMIT 3');
    console.log(tasks);
    
    console.log('\n数据检查完成！');
  } catch (error) {
    console.error('检查数据失败:', error);
    process.exit(1);
  } finally {
    await dataSource.destroy();
  }
  
  process.exit(0);
}

checkData(); 